package com.XinYun.Library.modules.show.controller.servlet;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import com.XinYun.Library.modules.show.controller.showImpl;
@WebServlet(name = "showServlet", urlPatterns = "/showServlet")
public class showServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求体数据
        BufferedReader reader = req.getReader();
        String readLine = reader.readLine();
        //将JSON字符转化为JAVA对象
        JSONObject jsonObject = JSON.parseObject(readLine);
        String value = jsonObject.getString("bookname");
        //调用方法，执行语句
        showImpl show = new showImpl();
        //传输
        try {
            String s = JSON.toJSONString(show.get(value));
            PrintWriter writer = resp.getWriter();
            writer.println(s);
            System.out.println(s);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
